<template>
  <button class="cl-button" :class="[`cl-button__${type}`]" :disabled="disabled || loading">
    <i v-if="loading" class="iconfont icon-Loading loading"></i>
    <i v-else-if="icon" :class="['iconfont', icon]"></i>
    <slot></slot>
  </button>
</template>

<script>
export default {
  name: 'Button',
  props: {
    type: {
      type: String,
      default: 'default'
    },
    icon: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    loading: {
      type: Boolean,
      default: false
    }
  }
}
</script>

<style lang="scss">
$primary-color: rgba(48, 131, 242, 1);

.cl-button {
  min-width: 56px;
  padding: 2px 12px;
  color: rgba(75, 79, 88, 1);
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  border-radius: 4px;
  outline: none;
  cursor: pointer;
  .iconfont {
    line-height: 1;
  }
  .loading {
    display: inline-block;
    font-size: 12px;
    animation: rotate 1.5s linear infinite;
  }
  &:disabled {
    opacity: 0.7;
    cursor: not-allowed;
  }
}
.cl-button ~ .cl-button {
  margin-left: 5px;
}
.cl-button__default {
  border: 1px solid rgba(195, 198, 214, 1);
  .iconfont {
    color: $primary-color;
  }
  &:not(:disabled):hover {
    background: rgba(48, 131, 242, .2);
    border-color: rgba(48, 131, 242, .4);
  }
}
.cl-button__primary {
  color: #fff;
  background-color: $primary-color;
  border: 1px solid $primary-color;
  &:not(:disabled):hover {
    background-color: rgba(48, 131, 242, .8);
    border-color: rgba(48, 131, 242, .8);
  }
}
.cl-button__text {
  color: $primary-color;
  border: none;
  &:disabled {
    color: rgba(75, 79, 88, 1);
  }
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(1turn);
  }
}
</style>